package 常用字符流;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class BufferedWriterExample {
    public static void main(String[] args) {
        try (FileWriter fileWriter = new FileWriter("output.txt");
             BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {

            // 写入字符串
            bufferedWriter.write("Hello, BufferedWriter!");

            // 写入换行
            bufferedWriter.newLine();

            // 写入另一行
            bufferedWriter.write("This is a new line.");

            // 不需要显式调用 flush()，close() 会自动调用
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}